package javax.core.common.tree;

import java.util.ArrayList;
import java.util.List;

/**
 * 树形结构抽象, V可以是任意的类型，
 * 对该类型进行的操作可以在 {@link TreeNodeUtil} 里面进行
 * @param <V>
 */
public class TreeNode<V> {
    private final boolean root;
    private final int depth;
    private V data;
    private List<TreeNode<V>> subNodeList;
    private TreeNode<V> parentNode;
    private TreeNode<V> previousNode;
    private TreeNode<V> nextNode;

    public TreeNode(boolean root, int depth, V data, TreeNode<V> parentNode) {
        this.root = root;
        this.depth = depth;
        this.data = data;
        this.parentNode = parentNode;
        subNodeList = new ArrayList<>();
    }

    public TreeNode(boolean root, int depth, V data, TreeNode<V> parentNode, TreeNode<V> previousNode) {
        this.root = root;
        this.depth = depth;
        this.data = data;
        this.parentNode = parentNode;
        this.previousNode = previousNode;
        subNodeList = new ArrayList<>();
    }

    public TreeNode<V> getParentNode() {
        return parentNode;
    }

    public V getData() {
        return data;
    }

    public void setData(V data) {
        this.data = data;
    }

    public boolean isRoot() {
        return root;
    }

    public List<TreeNode<V>> getSubNodeList() {
        return subNodeList;
    }

    public void setSubNodeList(List<TreeNode<V>> subNodeList) {
        this.subNodeList = subNodeList;
    }

    public TreeNode<V> getPreviousNode() {
        return previousNode;
    }

    public void setPreviousNode(TreeNode<V> previousNode) {
        this.previousNode = previousNode;
    }

    public TreeNode<V> getNextNode() {
        return nextNode;
    }

    public void setNextNode(TreeNode<V> nextNode) {
        this.nextNode = nextNode;
    }

    public int getDepth() {
        return depth;
    }
}
